#include<iostream>
using namespace std;
const int N = 1e4 + 10, M = 2e5 + 10;
int h[N], e[M], ne[M], idx;
int dis[N];
int n, m;
int s, t;
int q[M];
void add(int a, int b)
{
	e[idx] = b;
	ne[idx] = h[a];
	h[a] = idx++;
}
void bfs(int sx)
{
	memset(dis, -1, sizeof(dis));
	dis[sx] = 0;
	int hh = 0, tt = 0;
	q[0] = sx;
	while (hh <= tt) {
		int t = q[hh++];
		for (int i = h[t]; ~i; i = ne[i]) {
			int j = e[i];
			if (dis[j] == -1) {
				dis[j] = dis[t] + 1;
				q[++tt] = j;
			}
		}
	}	
}
int main()
{
	cin >> n >> m;
	memset(h, -1, sizeof(h));
	while (m--) {
		int a, b;
		cin >> a >> b;
		add(a, b);
		add(b, a);
	}
	cin >> s >> t;
	bfs(s);
	cout << dis[t] << endl;
	return 0;
}